package br.com.tecnove.random.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {

	private Button btnDefault;
	private Button btnDecision;
	private Button btnRange;
	private Button btnRpg;
	private Button btnString;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		btnDefault = (Button) findViewById(R.id.btnDefault);
		// btnDecision = (Button) findViewById(R.id.btnDecision);
		btnRange = (Button) findViewById(R.id.btnRange);
		btnString = (Button) findViewById(R.id.btnString);
		btnRpg = (Button) findViewById(R.id.btnRPG);

		btnDefault.setOnClickListener(this);
		// btnDecision.setOnClickListener(this);
		btnRange.setOnClickListener(this);
		btnString.setOnClickListener(this);
		btnRpg.setOnClickListener(this);
	}

	public void onClick(View view) {
		if (view instanceof Button) {
			Button but = (Button) view;
			Intent i = null;
			if (but == btnDefault) {
				i = new Intent(this, DefaultActivity.class);
				startActivity(i);
			} else if (but == btnDecision) {
				throw new UnsupportedOperationException(getString(R.string.not_supported));
			} else if (but == btnRange) {
				i = new Intent(this, RangeActivity.class);
				startActivity(i);
			} else if (but == btnRpg) {
				i = new Intent(this, RPGActivity.class);
				startActivity(i);
			} else if (but == btnString) {
				i = new Intent(this, StringActivity.class);
				startActivity(i);
			} else {
				throw new UnsupportedOperationException(getString(R.string.not_supported));
			}
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.appdefaultmenu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return ContextMenu.itemClicked(item, this);
	}
}